from bs4 import BeautifulSoup
import requests
import json

count = 0
for page in range(1, 3107):
    url = "https://read.douban.com/j/kind/"
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36",
        "Cookie": "bid=hxC8R3aCgWI; _ga_PRH9EWN86K=GS1.2.1724673194.1.0.1724673194.0.0.0; douban-fav-remind=1; ll='118237'; _vwo_uuid_v2=D6DBBC47FA8794F48EF917BC35363E7CB|d7fefa51a4ce24069846d66752fe652c; uaid='7a807b5672727ca21851d2376d6ec6e08add5b5f'; _ga=GA1.3.1355979370.1724671376; _pk_id.100001.a7dd=c34885cb7a615090.1724738165.; _ga=GA1.1.1355979370.1724671376; _ga_Y4GN1R87RG=GS1.1.1724750237.2.0.1724750243.0.0.0; viewed='36808795_36897362_36858240_36878790_36991441_36790192_36783021_36911739_36897630_36930293'; __utma=30149280.1355979370.1724671376.1724979325.1728435813.19; __utmz=30149280.1728435813.19.8.utmcsr=kdocs.cn|utmccn=(referral)|utmcmd=referral|utmcct=/; _gid=GA1.3.20890141.1729854223; _pk_ref.100001.a7dd=%5B%22%22%2C%22%22%2C1729854224%2C%22https%3A%2F%2Fbook.douban.com%2F%22%5D; _pk_ses.100001.a7dd=1; _ga_RXNMP372GL=GS1.1.1729854222.5.1.1729854376.60.0.0",
    }
    json = {"sort": "sales",
            "page": page,
            "kind": 1,
            "query": "\n    query getFilterWorksList($works_ids: [ID!]) {\n      worksList(worksIds: $works_ids) {\n        \n    id\n    isOrigin\n    isEssay\n    \n    title\n    cover(useSmall: false)\n    url\n    isBundle\n    coverLabel(preferVip: true)\n  \n    \n  url\n  title\n\n    \n  author {\n    name\n    url\n  }\n  origAuthor {\n    name\n    url\n  }\n  translator {\n    name\n    url\n  }\n\n    \n  abstract\n  authorHighlight\n  editorHighlight\n\n    \n    isOrigin\n    kinds {\n      \n    name @skip(if: true)\n    shortName @include(if: true)\n    id\n  \n    }\n    ... on WorksBase @include(if: true) {\n      wordCount\n      wordCountUnit\n    }\n    ... on WorksBase @include(if: false) {\n      inLibraryCount\n    }\n    ... on WorksBase @include(if: false) {\n      \n    isEssay\n    \n    ... on EssayWorks {\n      favorCount\n    }\n  \n    \n    \n    averageRating\n    ratingCount\n    url\n    isColumn\n    isFinished\n  \n  \n  \n    }\n    ... on EbookWorks @include(if: false) {\n      \n    ... on EbookWorks {\n      book {\n        url\n        averageRating\n        ratingCount\n      }\n    }\n  \n    }\n    ... on WorksBase @include(if: false) {\n      isColumn\n      isEssay\n      onSaleTime\n      ... on ColumnWorks {\n        updateTime\n      }\n    }\n    ... on WorksBase @include(if: true) {\n      isColumn\n      ... on ColumnWorks {\n        isFinished\n      }\n    }\n    ... on EssayWorks {\n      essayActivityData {\n        \n    title\n    uri\n    tag {\n      name\n      color\n      background\n      icon2x\n      icon3x\n      iconSize {\n        height\n      }\n      iconPosition {\n        x y\n      }\n    }\n  \n      }\n    }\n    highlightTags {\n      name\n    }\n    ... on WorksBase @include(if: false) {\n      fanfiction {\n        tags {\n          id\n          name\n          url\n        }\n      }\n    }\n  \n    \n  ... on WorksBase {\n    copyrightInfo {\n      newlyAdapted\n      newlyPublished\n      adaptedName\n      publishedName\n    }\n  }\n\n    isInLibrary\n    ... on WorksBase @include(if: false) {\n      \n    fixedPrice\n    salesPrice\n    isRebate\n    realPrice {\n      price\n      priceType\n    }\n  \n    }\n    ... on EbookWorks {\n      \n    fixedPrice\n    salesPrice\n    isRebate\n    realPrice {\n      price\n      priceType\n    }\n  \n    }\n    ... on WorksBase @include(if: true) {\n      ... on EbookWorks {\n        id\n        isPurchased\n        isInWishlist\n      }\n    }\n    ... on WorksBase @include(if: false) {\n      fanfiction {\n        fandoms {\n          title\n          url\n        }\n      }\n    }\n    ... on WorksBase @include(if: false) {\n      fanfiction {\n        kudoCount\n      }\n    }\n  \n      }\n    }\n  ",
            "variables": {}
            }

    response = requests.post(url, headers=headers, json=json)
    print(response.status_code)
    result = response.json()
    print(result['list'])
    for data in result['list']:
        count += 1
        print(count, data['title'])
